#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
	int m;
	scanf("%d", &m);
	int arr[m][2];
	int n = 0;
	int a = 0, b = 0;
	int x = 0;
	int chidao = 0, kuangke = 0;
	for (int i = 0; i < m; i++)
	{
		chidao=0,kuangke=0;
		x = i;
		scanf("%d", &n);
		for (int j = 0; j < n; j++)
		{
			scanf("%d:%d", &a, &b);
			if(a==7||(a==8&&b==0))
	        continue;
			else if(a==8&&b>0)
			{
				if(b<=5)
				{
					chidao++;
				}
				else 
				{
					kuangke++;
				}
			}
			else
			kuangke++;
		}
			arr[x][0]=chidao;
			arr[x][1]=kuangke;
	}
	for (int j = 0; j < m; j++)
	{
		for (int k = 0; k < 2; k++)
		{
			printf("%d ", arr[j][k]);
		}
		printf("\n");
	}
}
